import * as types from '../constants/loginTypes'

const initialState = {
  status: '正在登录...',
  isSuccess: false,
  user: {},
  serviceInfo: {},
  homeData: {},
  token: '',
  isLogout: false,
  errMsg: '',
	wxPublicNumber: ''
}

export default function login (state = initialState, action) {
  switch (action.type) {
    case types.LOGIN_IN_DOING:
      return {
        ...state,
        status: '正在登录...',
        isSuccess: false,
        errMsg: ''
      }
    case types.LOGIN_IN_DONE:
      return {
        ...state,
        status: '登录成功~',
        isSuccess: true,
        token: action.token
        // user: action.user
      }
    case types.LOGIN_IN_ERROR:
      return {
        ...state,
        status: '登录失败',
        isSuccess: false,
        user: null,
        errMsg: action.err
      }
    case types.LOGIN_CLEAR:
      return {
        ...initialState
      }
    case types.UPDATE_USERINFO:
      return {
        ...state,
        status: '更新用户信息成功',
        user: action.user
      }
    case types.UPDATE_TOKEN:
      return {
        ...state,
        status: '更新token成功',
        token: action.token
      }
    case types.UPDATE_SERVICEINFO:
      return {
        ...state,
        serviceInfo: action.info
      }
    case types.UPDATE_HOMEDATA:
      return {
        ...state,
        homeData: action.info
      }
		case types.UPDATE_WXINFO: 
			return {
				...state,
				wxPublicNumber: action.info
			}
    default:
      return state
  }
}
